//
//  UIView+FrameExtension.m
//  01frame
//
//  Created by 崔守良                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 on 16/4/7.
//  Copyright © 2016年 QF. All rights reserved.
//

#import "UIView+FrameExtension.h"

@implementation UIView (FrameExtension)

//设置属性的值
-(void)setX:(CGFloat)x{
    CGRect frame = self.frame;
    frame.origin.x = x;
    self.frame = frame;
}
-(void)setY:(CGFloat)y{
    CGRect frame = self.frame;
    frame.origin.y = y;
    self.frame = frame;
}
-(void)setCenterX:(CGFloat)centerX{
    CGPoint center = self.center;
    center.x = centerX;
    self.center = center;
}
-(void)setCenterY:(CGFloat)centerY{
    CGPoint center = self.center;
    center.y = centerY;
    self.center = center;
}
-(void)setWidth:(CGFloat)width{
    CGRect frame = self.frame;
    frame.size.width = width;
    self.frame = frame;
}
-(void)setHeight:(CGFloat)height{
    CGRect frame = self.frame;
    frame.size.height = height;
    self.frame = frame;
}
-(void)setRight:(CGFloat)right{
    CGRect frame = self.frame;
    CGFloat diff = right - (self.frame.origin.x + self.frame.size.width);//偏移量
    frame.origin.x += diff;
    self.frame = frame;
}
-(void)setBottom:(CGFloat)bottom{
    CGRect frame = self.frame;
    CGFloat diff = bottom - (self.frame.origin.y + self.frame.size.height);
    frame.origin.y += diff;
    self.frame = frame;

}



//获取相应的属性值
-(CGFloat)x{
    return self.frame.origin.x;
}
-(CGFloat)y{
    return self.frame.origin.y;
}
-(CGFloat)centerX{
    return self.center.x;
}
-(CGFloat)centerY{
    return self.center.y;
}
-(CGFloat)width{
    return self.frame.size.width;
}
-(CGFloat)height{
    return self.frame.size.height;
}
-(CGFloat)right{
    return self.frame.origin.x + self.frame.size.width;
}
-(CGFloat)bottom{
    return self.frame.origin.y + self.frame.size.height;
}


@end
